package com.sharker.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sharker.R;
import com.sharker.adapter.MyAdapter;
import com.sharker.models.data.TryData;
import com.sharker.network.SharkerParams;
import com.sharker.wiget.DividerItemDecoration;

import org.xutils.common.Callback;
import org.xutils.x;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 项目名称：Sharker-master
 * 类描述：
 * 创建人：${丁江楠}
 * 创建时间：2017/4/13 11:21
 * 修改人：${丁江楠}
 * 修改时间：2017/4/13 11:21
 * 修改备注：
 */
public class CourseDetaildfragment extends Fragment {
    @BindView(R.id.course_detail_recycler)
    RecyclerView mRecyclerview;
    Unbinder unbinder;
    private MyAdapter myAdapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.course_detail_item, null);
        unbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Bundle arguments = getArguments();
        String id = arguments.getString("id");
       // Toast.makeText(getActivity(),id,Toast.LENGTH_LONG).show();
        listTry();
    }

    void listTry() {
        SharkerParams params = new SharkerParams("list_try");
//      params.addBodyParameter("category","001");
        params.addBodyParameter("page_size", "20");
        params.addBodyParameter("page_index", "0");
        x.http().post(params, new Callback.CommonCallback<TryData>() {
            @Override
            public void onSuccess(final TryData result) {
                mRecyclerview.setLayoutManager(new LinearLayoutManager(getActivity()));
                mRecyclerview.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST));
                myAdapter = new MyAdapter(result.getTryList(), getActivity());
                mRecyclerview.setAdapter(myAdapter);
                //试听条目点击
                myAdapter.setMyOnitemListener(new MyAdapter.MyOnitemListener() {
                    @Override
                    public void OnItemclick(View view, int position) {
                  /*     Intent intent = new Intent(getActivity(), .class);
                   //  intent.putExtra("object_id", result.getTryList().get(position).getObject_id());
                        // startActivity(intent);*/
                    }
                });
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }



    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
